package cn.wolfcode.web.controller;

import cn.wolfcode.common.web.Result;
import cn.wolfcode.domain.SeckillProductVo;
import cn.wolfcode.service.ISeckillProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by lanxw
 * 秒杀商品信息查询
 */
@RestController
@RequestMapping("/seckillProduct")
@Slf4j
public class SeckillProductController {
    @Autowired
    private ISeckillProductService seckillProductService;

    /**
     *  线程 500 循环次数 10
     *  2000/qps
     *  4600/qps
     */
    @RequestMapping("/queryByTime")
    public Result<List<SeckillProductVo>> queryByTime(Integer time){
            System.out.println(time);
            return Result.success(seckillProductService.queryByTimeFromCache(time));
    }
    /**
     *  线程 500 循环次数 10
     *  280/qps  1200-1300之间
     *  4600/qps
     */
//    @RequestMapping("/queryByTime")
//    public Result<List<SeckillProductVo>> queryByTime(Integer time){
//        System.out.println(time);
//        List<SeckillProductVo> seckillProductVos = seckillProductService.queryByTime(time);
//        System.out.println(seckillProductVos);
//        return Result.success(seckillProductService.queryByTime(time));
//    }

    /**
     *
     * 线程 500 循环次数 10
     * 2600/qps  580/qps
     * 4700/qps
     */
//    @RequestMapping("/find")
//    public Result<SeckillProductVo> find(Integer time,Long seckillId){
//        System.out.println("已经跳入商品详情页面");
//        return Result.success(seckillProductService.find(time,seckillId));
//    }

    @RequestMapping("/find")
    public Result<SeckillProductVo> find(Integer time,Long seckillId){
        System.out.println("已经跳入商品详情页面");
        return Result.success(seckillProductService.findFromCache(time,seckillId));
    }
}
